from django.core.mail import send_mail
from django.conf import settings
from rest_framework.exceptions import APIException


def simple_send_email(subject, message, recipient_list):
    """
    简易版邮件发送函数

    参数:
        subject: 邮件主题
        message: 邮件正文（纯文本）
        recipient_list: 收件人列表，如['user@example.com']

    返回:
        成功返回True，失败抛出异常
    """
    try:
        # 使用Django内置的send_mail函数
        send_mail(
            subject=subject,
            message=message,
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=recipient_list,
            fail_silently=False  # 发送失败时抛出异常
        )
        return True
    except Exception as e:
        raise APIException(f"邮件发送失败: {str(e)}")